home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / apptbk / apptbook.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  28.9 KB  |  774 lines

  1. VERSION 2.00
  2. Begin Form ApptForm 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Appointments"
  5.    ClientHeight    =   5055
  6.    ClientLeft      =   1110
  7.    ClientTop       =   1545
  8.    ClientWidth     =   7320
  9.    Height          =   5460
  10.    Icon            =   APPTBOOK.FRX:0000
  11.    Left            =   1050
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   5055
  14.    ScaleWidth      =   7320
  15.    Top             =   1200
  16.    Width           =   7440
  17.    Begin PictureBox Panel3D2 
  18.       BackColor       =   &H00C0C0C0&
  19.       FontBold        =   0   'False
  20.       FontItalic      =   0   'False
  21.       FontName        =   "MS Sans Serif"
  22.       FontSize        =   8.25
  23.       FontStrikethru  =   0   'False
  24.       FontUnderline   =   0   'False
  25.       ForeColor       =   &H00800000&
  26.       Height          =   1755
  27.       Left            =   4500
  28.       ScaleHeight     =   1725
  29.       ScaleWidth      =   1605
  30.       TabIndex        =   12
  31.       Top             =   240
  32.       Width           =   1635
  33.       Begin PictureBox KindFrame 
  34.          BackColor       =   &H00C0C0C0&
  35.          ForeColor       =   &H00C0C0C0&
  36.          Height          =   675
  37.          Index           =   0
  38.          Left            =   120
  39.          ScaleHeight     =   645
  40.          ScaleWidth      =   645
  41.          TabIndex        =   16
  42.          Tag             =   "Phone"
  43.          Top             =   300
  44.          Width           =   675
  45.          Begin Image KindPict 
  46.             Height          =   480
  47.             Index           =   0
  48.             Left            =   90
  49.             Picture         =   APPTBOOK.FRX:0302
  50.             Top             =   90
  51.             Width           =   480
  52.          End
  53.       End
  54.       Begin PictureBox KindFrame 
  55.          BackColor       =   &H00C0C0C0&
  56.          ForeColor       =   &H00C0C0C0&
  57.          Height          =   675
  58.          Index           =   1
  59.          Left            =   120
  60.          ScaleHeight     =   645
  61.          ScaleWidth      =   645
  62.          TabIndex        =   15
  63.          Tag             =   "Travel"
  64.          Top             =   1020
  65.          Width           =   675
  66.          Begin Image KindPict 
  67.             Height          =   480
  68.             Index           =   1
  69.             Left            =   90
  70.             Picture         =   APPTBOOK.FRX:0604
  71.             Top             =   90
  72.             Width           =   480
  73.          End
  74.       End
  75.       Begin PictureBox KindFrame 
  76.          BackColor       =   &H00C0C0C0&
  77.          ForeColor       =   &H00C0C0C0&
  78.          Height          =   675
  79.          Index           =   2
  80.          Left            =   840
  81.          ScaleHeight     =   645
  82.          ScaleWidth      =   645
  83.          TabIndex        =   14
  84.          Tag             =   "Meeting"
  85.          Top             =   300
  86.          Width           =   675
  87.          Begin Image KindPict 
  88.             Height          =   480
  89.             Index           =   2
  90.             Left            =   90
  91.             Picture         =   APPTBOOK.FRX:0906
  92.             Top             =   90
  93.             Width           =   480
  94.          End
  95.       End
  96.       Begin PictureBox KindFrame 
  97.          BackColor       =   &H00C0C0C0&
  98.          ForeColor       =   &H00C0C0C0&
  99.          Height          =   675
  100.          Index           =   3
  101.          Left            =   840
  102.          ScaleHeight     =   645
  103.          ScaleWidth      =   645
  104.          TabIndex        =   13
  105.          Tag             =   "Lunch"
  106.          Top             =   1020
  107.          Width           =   675
  108.          Begin Image KindPict 
  109.             Height          =   480
  110.             Index           =   3
  111.             Left            =   90
  112.             Picture         =   APPTBOOK.FRX:0C08
  113.             Top             =   90
  114.             Width           =   480
  115.          End
  116.       End
  117.    End
  118.    Begin PictureBox Panel3D1 
  119.       BackColor       =   &H00C0C0C0&
  120.       ForeColor       =   &H00C0C0C0&
  121.       Height          =   2655
  122.       Left            =   4500
  123.       ScaleHeight     =   2625
  124.       ScaleWidth      =   2745
  125.       TabIndex        =   3
  126.       Top             =   2280
  127.       Width           =   2775
  128.       Begin CommandButton SaveButton 
  129.          Caption         =   "Save"
  130.          Default         =   -1  'True
  131.          FontBold        =   0   'False
  132.          FontItalic      =   0   'False
  133.          FontName        =   "MS Sans Serif"
  134.          FontSize        =   8.25
  135.          FontStrikethru  =   0   'False
  136.          FontUnderline   =   0   'False
  137.          Height          =   375
  138.          Left            =   120
  139.          TabIndex        =   10
  140.          Top             =   780
  141.          Width           =   735
  142.       End
  143.       Begin TextBox ApptText 
  144.          BackColor       =   &H00FFFFFF&
  145.          ForeColor       =   &H00000000&
  146.          Height          =   1275
  147.          Left            =   120
  148.          MultiLine       =   -1  'True
  149.          TabIndex        =   8
  150.          Top             =   1260
  151.          Width           =   2535
  152.       End
  153.       Begin PictureBox ApptTime 
  154.          BackColor       =   &H00C0C0C0&
  155.          FontBold        =   0   'False
  156.          FontItalic      =   0   'False
  157.          FontName        =   "MS Sans Serif"
  158.          FontSize        =   8.25
  159.          FontStrikethru  =   0   'False
  160.          FontUnderline   =   0   'False
  161.          ForeColor       =   &H00800000&
  162.          Height          =   315
  163.          Left            =   1500
  164.          ScaleHeight     =   285
  165.          ScaleWidth      =   1125
  166.          TabIndex        =   6
  167.          Top             =   840
  168.          Width           =   1155
  169.       End
  170.       Begin TextBox ApptType 
  171.          BackColor       =   &H00C0C0C0&
  172.          FontBold        =   0   'False
  173.          FontItalic      =   0   'False
  174.          FontName        =   "MS Sans Serif"
  175.          FontSize        =   8.25
  176.          FontStrikethru  =   0   'False
  177.          FontUnderline   =   0   'False
  178.          ForeColor       =   &H00800000&
  179.          Height          =   285
  180.          Left            =   1500
  181.          TabIndex        =   5
  182.          Top             =   480
  183.          Width           =   1155
  184.       End
  185.       Begin Image Image1 
  186.          Height          =   480
  187.          Left            =   1140
  188.          Picture         =   APPTBOOK.FRX:0F0A
  189.          Top             =   60
  190.          Width           =   480
  191.       End
  192.       Begin Label Label2 
  193.          Alignment       =   1  'Right Justify
  194.          BackColor       =   &H00C0C0C0&
  195.          Caption         =   "When:"
  196.          FontBold        =   0   'False
  197.          FontItalic      =   0   'False
  198.          FontName        =   "MS Sans Serif"
  199.          FontSize        =   8.25
  200.          FontStrikethru  =   0   'False
  201.          FontUnderline   =   0   'False
  202.          Height          =   255
  203.          Left            =   900
  204.          TabIndex        =   7
  205.          Top             =   840
  206.          Width           =   555
  207.       End
  208.       Begin Label Label1 
  209.          Alignment       =   1  'Right Justify
  210.          BackColor       =   &H00C0C0C0&
  211.          Caption         =   "Appointment type:"
  212.          FontBold        =   0   'False
  213.          FontItalic      =   0   'False
  214.          FontName        =   "MS Sans Serif"
  215.          FontSize        =   8.25
  216.          FontStrikethru  =   0   'False
  217.          FontUnderline   =   0   'False
  218.          Height          =   195
  219.          Left            =   120
  220.          TabIndex        =   4
  221.          Top             =   480
  222.          Width           =   1335
  223.       End
  224.    End
  225.    Begin Timer GridTimer 
  226.       Enabled         =   0   'False
  227.       Interval        =   100
  228.       Left            =   1260
  229.       Top             =   3780
  230.    End
  231.    Begin PictureBox ApptList 
  232.       BackColor       =   &H0080FFFF&
  233.       Height          =   2715
  234.       Left            =   120
  235.       ScaleHeight     =   2685
  236.       ScaleWidth      =   4245
  237.       TabIndex        =   0
  238.       Top             =   120
  239.       Width           =   4275
  240.    End
  241.    Begin Image TrashCan 
  242.       Height          =   480
  243.       Left            =   6480
  244.       Picture         =   APPTBOOK.FRX:120C
  245.       Top             =   900
  246.       Width           =   480
  247.    End
  248.    Begin Image TrashOpened 
  249.       Height          =   480
  250.       Left            =   1740
  251.       Picture         =   APPTBOOK.FRX:150E
  252.       Top             =   4380
  253.       Visible         =   0   'False
  254.       Width           =   480
  255.    End
  256.    Begin Image TrashClosed 
  257.       Height          =   480
  258.       Left            =   1260
  259.       Picture         =   APPTBOOK.FRX:1810
  260.       Top             =   4380
  261.       Visible         =   0   'False
  262.       Width           =   480
  263.    End
  264.    Begin Label DragArrow 
  265.       Caption         =   "DragArrow"
  266.       DragIcon        =   APPTBOOK.FRX:1B12
  267.       Height          =   255
  268.       Left            =   180
  269.       TabIndex        =   11
  270.       Top             =   4680
  271.       Visible         =   0   'False
  272.       Width           =   915
  273.    End
  274.    Begin Label MoveIcon 
  275.       Caption         =   "MoveIcon"
  276.       DragIcon        =   APPTBOOK.FRX:1E14
  277.       Height          =   255
  278.       Left            =   180
  279.       TabIndex        =   9
  280.       Top             =   4380
  281.       Visible         =   0   'False
  282.       Width           =   915
  283.    End
  284.    Begin Label SaveIcon 
  285.       Caption         =   "SaveIcon"
  286.       Height          =   255
  287.       Left            =   180
  288.       TabIndex        =   2
  289.       Top             =   4080
  290.       Visible         =   0   'False
  291.       Width           =   915
  292.    End
  293.    Begin Label NoDrag 
  294.       Caption         =   "NoDrag"
  295.       DragIcon        =   APPTBOOK.FRX:2116
  296.       Height          =   255
  297.       Left            =   180
  298.       TabIndex        =   1
  299.       Top             =   3780
  300.       Visible         =   0   'False
  301.       Width           =   915
  302.    End
  303. ' Variables used to manage grid
  304. Dim IgnoreRowChange As Integer
  305. Dim GridInvertRect As RECT
  306. Dim GridInverted As Integer
  307. Dim GridDropRow As Integer
  308. ' Drag mode constants to keep track of dragging activity.
  309. Dim DragType As Integer         ' type of object being dragged
  310. Dim Dragging As Integer         ' TRUE when dragging is in progress
  311. Dim DragIndex As Integer        ' Optional index of dragged obj
  312. Dim DragRow As Integer          ' Optional row being dragged in grid
  313. ' Miscellaneous variables
  314. Dim valid%                      ' used as return for DragValid
  315. ' Bitmasks to describe valid drag objects
  316. Const MASK_NEWAPPT = 1      ' a new appointment
  317. Const MASK_OLDAPPT = 2      ' an old appointment
  318. Const MASK_NONE = 0         ' mask used where no drops are allowed
  319. Function ApiRectFromPoint (ctl As Grid, X As Single, Y As Single, r As RECT) As Integer
  320.     ' Given a grid control and a coordinate position, this routine
  321.     ' returns a Windows RECT structure containing the pixel
  322.     ' coordinates of the row being pointed at.  The row number is
  323.     ' returned, or -1, indicating that no row is being pointed at.
  324.     Dim curRow As Integer
  325.     Dim totHeight As Single
  326.     Dim topLocation As Single
  327.     ' Loop through each row, accumulating row height until we reach
  328.     ' the row containing the point.
  329.     For curRow = 0 To ctl.Rows - 1
  330.         topLocation = totHeight
  331.         totHeight = totHeight + ctl.RowHeight(curRow) + Screen.TwipsPerPixelY
  332.         
  333.         If Y < totHeight Then
  334.             ' Convert the twips values into pixel coordinates
  335.             ApiRectFromPoint = curRow
  336.             r.top = topLocation / Screen.TwipsPerPixelY
  337.             r.bottom = totHeight / Screen.TwipsPerPixelY
  338.             r.left = 0
  339.             r.right = ctl.Width / Screen.TwipsPerPixelY
  340.             Exit Function
  341.         End If
  342.     Next curRow
  343.     ApiRectFromPoint = -1           ' indicate failure
  344. End Function
  345. Sub ApptEdit ()
  346.     ' This subroutine moves the data in the current grid row into
  347.     ' the "post-it" editing area.
  348.     Dim aText As String
  349.     Dim colonPos As Integer
  350.     ' This routine copies appointment data to the edit window
  351.     ApptList.Col = 1
  352.     aText = ApptList.Text
  353.     colonPos = InStr(aText, ":")
  354.     ' If no colon, there's no appointment, so clear the post-it
  355.     ' area.  If there is a colon, fill in the information.
  356.     If colonPos = 0 Then
  357.         ApptText.Text = ""
  358.         ApptTime.Text = Format$(0, ApptTime.Format)
  359.         ApptType.Text = ""
  360.     Else
  361.         ApptType.Text = Left$(aText, colonPos - 1)
  362.         ApptText.Text = Mid$(aText, colonPos + 2)
  363.         ApptList.Col = 0
  364.         ApptTime.Text = Format$(ApptList.Text, ApptTime.Format)
  365.     End If
  366. End Sub
  367. Sub ApptList_DragDrop (Source As Control, X As Single, Y As Single)
  368.     ' Drop a new appointment or existing appointment at a new
  369.     ' row position.
  370.     Dim aText As String
  371.     Dim i%
  372.     If Not EndDragMode(MASK_NEWAPPT Or MASK_OLDAPPT) Then Exit Sub
  373.     UnhighlightRow
  374.     IgnoreRowChange = True
  375.     If DragType = MASK_NEWAPPT Then
  376.         ApptList.Col = 1
  377.         ApptList.Row = GridDropRow
  378.         ApptList.Text = Source.Tag & ": "
  379.         ApptEdit
  380.     Else
  381.         ApptList.Col = 0
  382.         ApptList.Row = GridDropRow
  383.         aText = ApptList.Text
  384.         ApptList.Row = DragRow
  385.         i% = ChangeApptTime(TimeValue(aText))
  386.     End If
  387.     IgnoreRowChange = False
  388.     ApptText.SetFocus
  389. End Sub
  390. Sub ApptList_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  391.     ' When dragging over the grid, both new and old appointments
  392.     ' are considered.  For both cases, we unhighlight the current
  393.     ' destination row upon leaving the drop zone, and assure that
  394.     ' the row under the point is highlighted otherwise.
  395.     If Not DragValid(Source, MASK_NEWAPPT Or MASK_OLDAPPT, State) Then
  396.         Exit Sub
  397.     End If
  398.     Select Case State
  399.         Case LEAVE
  400.             UnhighlightRow
  401.         Case Else
  402.             GridDropRow = HighlightRowAtPoint(X, Y)
  403.     End Select
  404. End Sub
  405. Sub ApptList_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  406.     ' We take charge of the mouse down event to initiate dragging
  407.     ' ourselves.  First, the cursor must be in column 1.  Next,
  408.     ' the row must contain a valid appointment to be grabbed
  409.     ' (identified by the presence of a colon in the cell).
  410.     If AtGridCol(ApptList, X, Y) > 0 Then
  411.         If InStr(ApptList.Text, ":") <> 0 Then
  412.             ' The timer will now count down.  This allows the user
  413.             ' to easily click, or "press" the mouse.  The Timer
  414.             ' event handles the drag initialization.
  415.             GridTimer.Enabled = True
  416.         End If
  417.     End If
  418. End Sub
  419. Sub ApptList_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  420.     ' Be sure the timer is disabled so that a click doesn't
  421.     ' initiate a drag.  If it's already disabled, it doesn't matter.
  422.     GridTimer.Enabled = False
  423. End Sub
  424. Sub ApptList_RowColChange ()
  425.     ' Whenever the row changes, move the highlight to track the
  426.     ' current cell.
  427.     ApptList.SelStartRow = ApptList.Row
  428.     ApptList.SelEndRow = ApptList.Row
  429.     ' IgnoreRowChange means that we're setting Col or Row somewhere
  430.     ' else in the code and we don't want ApptEdit to be called.
  431.     ' Otherwise, the user changed the row and we update the
  432.     ' "post-it" area.
  433.     If Not IgnoreRowChange Then
  434.         IgnoreRowChange = True
  435.         ApptEdit
  436.         IgnoreRowChange = False
  437.     End If
  438. End Sub
  439. Sub ApptText_DragDrop (Source As Control, X As Single, Y As Single)
  440.     valid% = EndDragMode(MASK_NONE)
  441. End Sub
  442. Sub ApptText_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  443.     valid% = DragValid(Source, MASK_NONE, State)
  444. End Sub
  445. Sub ApptTime_DragDrop (Source As Control, X As Single, Y As Single)
  446.     valid% = EndDragMode(MASK_NONE)
  447. End Sub
  448. Sub ApptTime_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  449.     valid% = DragValid(Source, MASK_NONE, State)
  450. End Sub
  451. Sub ApptTime_ValidationError (InvalidText As String, StartPosition As Integer)
  452.     MsgBox "Invalid time"
  453.     ApptTime.SetFocus
  454. End Sub
  455. Sub ApptType_DragDrop (Source As Control, X As Single, Y As Single)
  456.     ' Accept a drop only for a NEWAPPT icon, otherwise the
  457.     ' operation will be cancelled.
  458.     If EndDragMode(MASK_NEWAPPT) Then
  459.         ApptType.Text = Source.Tag
  460.     End If
  461. End Sub
  462. Sub ApptType_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  463.     valid% = DragValid(Source, MASK_NEWAPPT, State)
  464. End Sub
  465. Sub ApptType_KeyPress (KeyAscii As Integer)
  466.     ' Don't allow a colon to be entered, since we use a colon to
  467.     ' separate the appointment "kind" from the text.
  468.     If KeyAscii = Asc(":") Then
  469.         Beep
  470.         KeyAscii = 0
  471.     End If
  472. End Sub
  473. Function AtGridCol (ctl As Control, X As Single, Y As Single)
  474.     ' Given a point on a grid control, in twips, this routine
  475.     ' returns the column number where the point is located, or
  476.     ' -1 indicating the point is outside the grid.
  477.     Dim curCol As Integer
  478.     Dim totWidth As Single
  479.     ' Loop through each column, accumulating column width until we
  480.     ' reach the column containing the point.
  481.     For curCol = 0 To ctl.Cols - 1
  482.         
  483.         totWidth = totWidth + ctl.ColWidth(curCol) + Screen.TwipsPerPixelX
  484.         
  485.         If X < totWidth Then
  486.             AtGridCol = curCol
  487.             Exit Function
  488.         End If
  489.     Next curCol
  490.     AtGridCol = -1          ' not found
  491. End Function
  492. Sub BeginDragMode (ctl As Control, objType As Integer)
  493.     ' Whenever a drag is about to start, this routine is called.
  494.     ' The type mask of the drag is flagged, and we remember that
  495.     ' dragging is in progress.   This routine MUST be matched
  496.     ' by an EndDragMode function call.
  497.     DragType = objType
  498.     Dragging = True
  499.     ' Start the drag process
  500.     ctl.Drag BEGIN_DRAG
  501. End Sub
  502. Function ChangeApptTime (newtime As Variant) As Integer
  503.     ' Given a new time for an appointment at the current row, this
  504.     ' routine moves the appointment to the new location in the
  505.     ' grid.
  506.     Dim trow As Integer
  507.     Dim oldAppt As String
  508.     trow = TimeRow(newtime)
  509.     ' If we're already there, then do nothing and return False,
  510.     ' indicating no row change occurred.
  511.     If trow = ApptList.Row Then
  512.         ChangeApptTime = False
  513.         Exit Function
  514.     End If
  515.     ChangeApptTime = True
  516.     IgnoreRowChange = True
  517.     ' Actually move the row.
  518.     ApptList.Col = 1
  519.     oldAppt = ApptList.Text
  520.     ApptList.Text = ""
  521.     ApptList.Row = trow
  522.     ApptList.Text = oldAppt
  523.     ApptEdit            ' move the data to the post-it area
  524.     IgnoreRowChange = False
  525. End Function
  526. Function DragValid (src As Control, mask As Integer, State As Integer) As Integer
  527.     ' This function is called by an object's DragOver event to
  528.     ' automatically change the drag cursor to the "no drop"
  529.     ' cursor if necessary.  It also returns True if the object
  530.     ' can legally be dropped according to the input mask.
  531.     If (mask And DragType) Then
  532.         DragValid = True
  533.         Exit Function
  534.     End If
  535.     ' This is not a valid drag.  Return False, but also change the
  536.     ' object's drag icon to the NoDrag icon (remembering the old
  537.     ' value for later restore when we exit this object).
  538.     DragValid = False
  539.     Select Case State
  540.         
  541.         Case ENTER
  542.             ' Entering, remember old icon
  543.             SaveIcon.DragIcon = src.DragIcon
  544.             src.DragIcon = NoDrag.DragIcon
  545.         Case LEAVE
  546.             
  547.             ' Exiting, restore old icon
  548.             src.DragIcon = SaveIcon.DragIcon
  549.     End Select
  550.                 
  551. End Function
  552. Function EndDragMode (mask As Integer) As Integer
  553.     ' This function is called when a drag has ended, either
  554.     ' successfully or unsuccessfully.  This routine removes any
  555.     ' user feedback related to the drag operation and returns
  556.     ' TRUE if the passed mask matches the dragged object.
  557.     Select Case DragType
  558.         Case MASK_NEWAPPT
  559.             ' If a "new appointment" icon was dragged, change the
  560.             ' frame background to LTGREY again so that the drag
  561.             ' is officially over.
  562.             KindFrame(DragIndex).BackColor = LTGREY
  563.         Case MASK_OLDAPPT
  564.             ' If this is an item dragged from the grid, refresh
  565.             ' the grid in case the drag ended outside the grid
  566.             ' frame (and the inverted row remains).
  567.             ApptList.Refresh
  568.     End Select
  569.     Dragging = False
  570.     EndDragMode = (mask And DragType) <> 0
  571. End Function
  572. Sub Form_DragDrop (Source As Control, X As Single, Y As Single)
  573.     ' Ignore drops which occur on the form
  574.     valid% = EndDragMode(MASK_NONE)
  575. End Sub
  576. Sub Form_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  577.     ' Assure that the "no drop" icon is displayed when passing
  578.     ' over the form.
  579.     valid% = DragValid(Source, MASK_NONE, State)
  580. End Sub
  581. Sub Form_Load ()
  582.     Dim curTime As Variant
  583.     Dim curRow As Integer
  584.     Dim rowMax As Integer
  585.     ' Initialize the grid column widths, and set the height of
  586.     ' the list so it displays all times entered.
  587.     rowMax = (Prefs.timeEnd - Prefs.timeStart) / Prefs.timeIncrement
  588.     ApptList.ColWidth(0) = ApptForm.TextWidth("XX:XX XX")
  589.     ApptList.ColWidth(1) = ApptList.Width - ApptList.ColWidth(0)
  590.     ApptList.Height = (ApptList.RowHeight(0) + Screen.TwipsPerPixelY) * rowMax
  591.     IgnoreRowChange = True
  592.     ApptList.Rows = rowMax
  593.     ApptList.Col = 0
  594.     ' Fill the leftmost column with appointment times.
  595.     For curTime = Prefs.timeStart To Prefs.timeEnd Step Prefs.timeIncrement
  596.         ApptList.Row = curRow
  597.         ApptList.Text = Format$(curTime, "hh:mm am/pm")
  598.         curRow = curRow + 1
  599.     Next curTime
  600.     IgnoreRowChange = False
  601.     ApptList.Row = 0
  602. End Sub
  603. Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  604.     ' Since we can't trap a "drop" which occurs outside of our
  605.     ' application, this is a pretty good solution.  Whenever the
  606.     ' cursor passes over the form, if we're still dragging check
  607.     ' to see if the button is now up.  If so, just cancel the
  608.     ' operation
  609.     If Dragging Then
  610.         If (Button And LEFT_BUTTON) = 0 Then
  611.             valid% = EndDragMode(MASK_NONE)
  612.         End If
  613.     End If
  614. End Sub
  615. Sub GridTimer_Timer ()
  616.     ' When the timer is triggered, the user has been holding the
  617.     ' mouse down over a grid row for a "press" duration.  Now,
  618.     ' initiate a drag operation.
  619.     ' Reset the column to the one with the text in it.
  620.     IgnoreRowChange = True
  621.     ApptList.Col = 1
  622.     IgnoreRowChange = False
  623.     ' Indicate we're doing an "old appointment" drag.
  624.     DragRow = ApptList.Row
  625.     ApptList.DragIcon = MoveIcon.DragIcon
  626.     BeginDragMode ApptList, MASK_OLDAPPT
  627.     GridTimer.Enabled = False
  628. End Sub
  629. Function HighlightRowAtPoint (X As Single, Y As Single) As Integer
  630.     ' If the ApplList grid was highlighted (according to the
  631.     ' GridInverted variable), then unhighlight the old location and
  632.     ' highlight the new one.  Instead of a row number, a point within
  633.     ' the grid is passed.  The row number is returned, or -1, meaning
  634.     ' that the point was outside the grid.
  635.     Dim newrect As RECT
  636.     Dim rownum As Integer
  637.     Dim gridDC As Integer
  638.     rownum = ApiRectFromPoint(ApptList, X, Y, newrect)
  639.     HighlightRowAtPoint = rownum
  640.     ' Don't rehighlight the current row, just exit.
  641.     If rownum >= 0 And GridInverted And newrect.top = GridInvertRect.top Then Exit Function
  642.     ' Use the Windows API call InvertRect to invert the row we're
  643.     ' passing above.
  644.     gridDC = GetDC(ApptList.hWnd)
  645.     If GridInverted Then InvertRect gridDC, GridInvertRect
  646.     GridInverted = True
  647.     If rownum >= 0 Then
  648.         GridInvertRect = newrect
  649.         InvertRect gridDC, GridInvertRect
  650.         GridInverted = True
  651.     Else
  652.         GridInverted = False
  653.     End If
  654.     gridDC = ReleaseDC(ApptList.hWnd, gridDC)
  655. End Function
  656. Sub Image1_DragDrop (Source As Control, X As Single, Y As Single)
  657.     valid% = EndDragMode(MASK_NONE)
  658. End Sub
  659. Sub Image1_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  660.     valid% = DragValid(Source, MASK_NONE, State)
  661. End Sub
  662. Sub KindFrame_DragDrop (Index As Integer, Source As Control, X As Single, Y As Single)
  663.     valid% = EndDragMode(MASK_NONE)
  664. End Sub
  665. Sub KindFrame_DragOver (Index As Integer, Source As Control, X As Single, Y As Single, State As Integer)
  666.     valid% = DragValid(Source, MASK_NEWAPPT, State)
  667. End Sub
  668. Sub KindPict_DragDrop (Index As Integer, Source As Control, X As Single, Y As Single)
  669.     valid% = EndDragMode(MASK_NONE)
  670. End Sub
  671. Sub KindPict_DragOver (Index As Integer, Source As Control, X As Single, Y As Single, State As Integer)
  672.     valid% = DragValid(Source, MASK_NEWAPPT, State)
  673. End Sub
  674. Sub KindPict_MouseDown (Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  675.     ' When the left button goes down over an "appointment type"
  676.     ' icon, drag its image in NEWAPPT mode.  Copy the DragIcon
  677.     ' each time, since it may still be set to the "no drop" icon
  678.     ' from a previous cancellation.
  679.     If Button And LEFT_BUTTON Then
  680.         KindFrame(Index).DragIcon = DragArrow.DragIcon
  681.         BeginDragMode KindFrame(Index), MASK_NEWAPPT
  682.         KindFrame(Index).BackColor = CYAN
  683.         
  684.         ' Save the index, we'll need it in EndDragMode
  685.         DragIndex = Index
  686.     End If
  687. End Sub
  688. Sub Label1_DragDrop (Source As Control, X As Single, Y As Single)
  689.     valid% = EndDragMode(MASK_NONE)
  690. End Sub
  691. Sub Label1_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  692.     valid% = DragValid(Source, MASK_NONE, State)
  693. End Sub
  694. Sub Label2_DragDrop (Source As Control, X As Single, Y As Single)
  695.     valid% = EndDragMode(MASK_NONE)
  696. End Sub
  697. Sub Label2_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  698.     valid% = DragValid(Source, MASK_NONE, State)
  699. End Sub
  700. Sub Panel3D1_DragDrop (Source As Control, X As Single, Y As Single)
  701.     valid% = EndDragMode(MASK_NONE)
  702. End Sub
  703. Sub Panel3D1_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  704.     valid% = DragValid(Source, MASK_NONE, State)
  705. End Sub
  706. Sub SaveButton_Click ()
  707.     ' Save all data in the post-it area to the grid.
  708.     Dim i%
  709.     IgnoreRowChange = True
  710.     ApptList.Col = 1
  711.     ' We can only save if there's an appointment on the current
  712.     ' grid row already (at least a blank one).
  713.     If InStr(ApptList.Text, ":") = 0 Then
  714.         MsgBox "No appointment at current row"
  715.         Exit Sub
  716.     End If
  717.     ApptList.Text = ApptType.Text & ": " & ApptText.Text
  718.     IgnoreRowChange = False
  719.     ' If the time was changed manually, then move the row to the new
  720.     ' location.
  721.     i% = ChangeApptTime(TimeValue(ApptTime.Text))
  722. End Sub
  723. Sub SaveButton_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  724.     valid% = DragValid(Source, MASK_NONE, State)
  725. End Sub
  726. Function TimeRow (thetime As Variant) As Integer
  727.     ' Given a time value, return the row number within the grid
  728.     ' where the specified time slot is located.
  729.     TimeRow = (thetime - Prefs.timeStart) / Prefs.timeIncrement
  730. End Function
  731. Sub TrashCan_DragDrop (Source As Control, X As Single, Y As Single)
  732.     ' The trash can only accepts drops for "old appointments" from
  733.     ' the grid.
  734.     If EndDragMode(MASK_OLDAPPT) Then
  735.         ' Get rid of feedback
  736.         TrashCan.Picture = TrashClosed.Picture
  737.         ' Clear the grid row and update the post-it area
  738.         IgnoreRowChange = True
  739.         
  740.         ApptList.Row = DragRow
  741.         ApptList.Col = 1
  742.         ApptList.Text = ""
  743.         ApptEdit
  744.         ApptList.SetFocus
  745.         IgnoreRowChange = False
  746.     End If
  747. End Sub
  748. Sub TrashCan_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  749.     ' Provide feedback by "opening the trashcan" whenever an
  750.     ' old appointment is dragged over the trash.
  751.     If DragValid(Source, MASK_OLDAPPT, State) Then
  752.         Select Case State
  753.             Case ENTER
  754.                 ' Open when entering
  755.                 TrashCan.Picture = TrashOpened.Picture
  756.             Case LEAVE
  757.                 ' Close when leaving
  758.                 TrashCan.Picture = TrashClosed.Picture
  759.         End Select
  760.     End If
  761. End Sub
  762. Sub UnhighlightRow ()
  763.     ' If the ApptList grid is highlighted (according to the
  764.     ' GridInverted flag), then unhighlight it, otherwise do
  765.     ' nothing.
  766.     Dim gridDC As Integer
  767.     If Not GridInverted Then Exit Sub
  768.     ' Use the invert rectangle saved by HighlightRowAtPoint
  769.     gridDC = GetDC(ApptList.hWnd)
  770.     InvertRect gridDC, GridInvertRect
  771.     gridDC = ReleaseDC(ApptList.hWnd, gridDC)
  772.     GridInverted = False
  773. End Sub
  774.